<div class="main-content">
	<style type="text/css">
		.body-row{width: 100%;margin: auto;}
	</style>
	<!-- Main content -->
    <div class="page-content">
    	<div class="row">
    	    <div class="page-header">
    			<h1>加油站管理</h1>
    		</div>
    		<div class="col-xs-12">
            	<?php if (in_array('admin/gasstation/add_gasstation', $_SESSION['ACL_ARR'])):?>
            	<a class="btn btn-info btn-sm" href="<?php echo base_url()."admin/gasstation/add_gasstation"?>"><i class="icon-copy"></i>新增</a>
                <?php endif;?>
                <?php if (in_array('admin/gasstation/del_gasstation', $_SESSION['ACL_ARR'])):?>
                <a href="javascript:void(0)" onclick="delSomeModal()" data-toggle="modal" class="btn btn-danger btn-sm"><i class="icon-trash"></i>删除</a>
            	<?php endif;?>
            	<a href="javascript:void(0)" onclick="getGasstationSettlement()" data-toggle="modal" class="btn btn-info btn-sm"><i class="icon-trash"></i>导出结算记录</a>
            	<a href="<?php echo base_url().'admin/gasstation/qiao_hexiao'?>"  data-toggle="modal" class="btn btn-info btn-sm"><i class="icon-trash"></i>壳牌核销</a>
            	<select id="third_station">
            		<option <?php if($third_station == ''):?>selected="selected"<?php endif?> value="">全部油站</option>
            		<option <?php if($third_station === '0'):?>selected="selected"<?php endif?> value="0">钉铛油站</option>
            		<option <?php if($third_station === '1'):?>selected="selected"<?php endif?> value="1">信联油站</option>
            	</select>
            	<script type="text/javascript">
            		$('#third_station').change(function(){
            			var type = $(this).val();
            			location.href="<?php echo base_url().'admin/gasstation?third_station='?>"+type;
            		})
            	</script>
            	<button id="pre_update"  data-toggle="modal" class="btn btn-info btn-sm">预约修改</button>
            </div>
            <div class=" col-md-12 col-sm-12 col-xs-12 form">
                <div class="row">
                <form action="<?php echo base_url().'admin/gasstation/index'?>" method="get">
                   <div class="wh">
                    	<label>加油站名称：</label>
                        <input type="text"  name="gasstation_name" value="<?php if (isset($gasstation_name))echo $gasstation_name;?>"/>
                        
                   </div>
                   <div class="wh">
                   		<button class="btn btn-sm btn-info" type="submit"><i class="icon-search"></i>查询</button>
                   </div>
                </form>
                </div>
			</div>
			<div class="col-xs-12 margin_t margin_b">
				<div class="table-responsive  tab">
				<form action="<?php echo base_url()."admin/gasstation/del_some_gasstation"?>" method="post" id="delForm">
					<table id="sample-table-1" class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th class="center" style="width: 3%;">
									<label>
										<input type="checkbox" class="ace" />
										<span class="lbl"></span>
									</label>
								</th>
								<th>序号</th>
								<th>加油站名称</th>
								<th>加油站地址</th>
								<th>二维码</th>
                                <th>创建时间</th>
                                <th style="width: 25%;">操作</th>
							</tr>
						</thead> 
						<tbody>
						<?php if (isset($result)&&count($result)>0){
                            	foreach ($result as $gasstation){
                            	    if ($gasstation->del_flg==0){
                            	?>
							<tr>
								<td class="center">
                                	<p>
									<label>
										<input type="checkbox" class="ace" name="num[]" value="<?php echo $gasstation->id;?>"/>
										<span class="lbl"></span>
									</label>
                                    </p>
								</td>
								<td><p><?php echo $gasstation->id;?></p></td>
								<td><p><?php echo $gasstation->gasstation_name;?></p></td>
								<td><p><?php echo $gasstation->address;?></p></td>
								<td><p>
								<?php if ($gasstation->qrcode_url != ''){?>
								<a href="<?php echo base_url().'admin/gasstation/download_img/'.$gasstation->id;?>">
                   					<img src="<?php echo base_url().$gasstation->qrcode_url;?>" style="border-radius: 0%;width: 100px;">
               					</a>
                				<?php } else {?>
                  					 暂无二维码
               					<?php }?>
								</p></td>
								<td><p><?php echo $gasstation->create_time;?></p></td>
								<td><p> 
								<?php if (in_array('admin/gasstation/edit_gasstation', $_SESSION['ACL_ARR'])):?>         
								<a class="btn btn-sm btn-info" href="<?php echo base_url().'admin/gasstation/edit_gasstation/'.$gasstation->id;?>" style="margin: 0.05in"><i class="icon-edit"></i>编辑</a>
                                <?php endif;?>
                                <?php if (in_array('admin/gasolinemodel/index', $_SESSION['ACL_ARR'])):?>
								<a class="btn btn-sm btn-info" href="<?php echo base_url().'admin/gasolinemodel/index/'.$gasstation->id;?>" style="margin: 0.05in"><i class="icon-eye-open"></i>油号管理</a>
                                <?php endif;?>
                                
								<?php if($gasstation->third_gasstation == 0):?><a href="<?php echo base_url().'admin/gasstation/qrcode_gasstation/'.$gasstation->id?>" class="btn btn-sm btn-info"><i class="icon-qrcode"></i>生成二维码</a><?php endif?>
                                
                            	<a class="btn btn-sm btn-info" href="<?php echo base_url().'admin/gasstation/order/' .$gasstation->id;?>" style="margin: 0.05in"><i class="icon-list"></i>订单列表
								</a>
                                
								<a class="btn btn-sm btn-info" href="<?php echo base_url().'admin/gasstation/settlement/' .$gasstation->id;?>" style="margin: 0.05in">
									<i class="icon-list"></i>结算管理
								</a>
                                
								<?php if($gasstation->third_gasstation == 0):?><a class="btn btn-sm btn-info" href="<?php echo base_url().'admin/gasstation/activity/' .$gasstation->id;?>">
									<i class="icon-briefcase"></i>活动管理
								</a><?php endif?>
                                
                                
                                
                                	<?php if (in_array('admin/gasstation/del_gasstation', $_SESSION['ACL_ARR'])):?>
                                    <a href="javascript:void(0)" onclick="delmodal('<?php echo $gasstation->id;?>')" data-toggle="modal" class="btn btn-danger btn-sm" style="margin: 0.05in"><i class="icon-trash"></i>删除</a>
                                	<?php endif;?>
									<?php if ($gasstation->use_type == 0){?>
                                         <a href="javascript:void(0)" onclick="use_gasstation('<?php echo $gasstation->id;?>',0)" data-toggle="modal" class="btn btn-danger btn-sm" style="margin: 0.05in">停用</a>
                                    <?php } else {?>
                                         <a href="javascript:void(0)" onclick="use_gasstation('<?php echo $gasstation->id;?>',1)" data-toggle="modal" class="btn btn-sm btn-info" style="margin: 0.05in">启用</a>
                                    <?php }?>
                                
                                
                                </p>
                                </td>
                                </tr>
    						<?php }}
                            }else{?>
                            <tr>
                            	<td colspan="12">无数据</td>
                            </tr>
                            <?php }?>
                            </tbody>
                         </table>
                     </form>
                     </div><!-- /.table-responsive -->
            	</div>
            	<div class="col-sm-12">
                	<div class="modal-footer no-margin-top">
	                	<div class="pull-left record">
							共<?php echo $count;?>条记录
	                    </div>
                		<?php if (isset($page))echo $page;?>
                	</div>
                </div>
            </div><!-- /.row -->
		</div><!-- /.page-content -->
	</div><!-- /.main-content -->
	<div id="delModal" class="modal fade" role="dialog" aria-hidden="true">
		<div class="modal-dialog" style="width: 300px">
			<div class="modal-content">
				<div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				  <h3>提示信息</h3>
				</div>
				<div class="modal-body">
				  <p>确定要删除该加油站吗？</p>
				</div>
				<div class="modal-footer">
				  <a id="delbtn" href="#" class="btn btn-danger">确定</a>
				  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
				</div>
			</div>
		</div>
	</div>
	<div id="userG" class="modal fade" role="dialog" aria-hidden="true">
		<div class="modal-dialog" style="width: 300px">
			<div class="modal-content">
				<div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				  <h3>提示信息</h3>
				</div>
				<div class="modal-body">
				  <p id="user_title" name="user_title">确定停用该加油站吗</p>
				</div> 
				<div class="modal-footer">
				  <a id="usebtn" href="#" class="btn btn-danger">确定</a>
				  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
				</div>
			</div>
		</div>
	</div>
	
	<div id="delsomeModal" class="modal fade" role="dialog" aria-hidden="true">
		<div class="modal-dialog" style="width: 300px">
			<div class="modal-content">
				<div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				  <h3>提示信息</h3>
				</div>
				<div class="modal-body">
				  <p>确定要删除所选加油站吗？</p>
				</div>
				<div class="modal-footer">
				  <button id="delsomebtn" type="submit" class="btn btn-danger">确定</button>
				  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
				</div>
			</div>
		</div>
	</div>
	<!-- 预约修改油站价 -->
	<div id="pre_plan" class="modal fade" role="dialog" aria-hidden="true">
		<div class="modal-dialog" style="width: 300px">
			<div class="modal-content">
				<div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				  <h3>提示信息</h3>
				</div>
				<div class="modal-body">
				  	<p id="user_title" name="user_title">设置时间及降幅</p>
				  	<div class='body-row'><span><label for="de_price">降幅:</label><input type="text"  style="height: 24px;" id="de_price" /></span></div>
    				<div class='body-row'><span><label for="time">时间:</label><input  style="height: 24px;" lay-key='3' id="time" /></span></div>
    				<div class='body-row'><span><label for="oil_no">油号:</label><select id="oil_no">
    					<option value="">请选择</option>
    					<option value="11">#92</option>
    					<option value="12">#95</option>
    					<option value="13">#98</option>
    					<option value="14">#0</option>
    				</select></span></div>
				</div> 
				<div class="modal-footer">
				  <a id="plan_button" href="#" class="btn btn-danger">确定</a>
				  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
				</div>
			</div>
		</div>
	</div>

<script type="text/javascript">
	layui.use('laydate', function(){
	  	var laydate = layui.laydate;
		//执行一个laydate实例
		laydate.render({
		    elem: '#time', //指定元素
		    type: 'datetime'
		});
	});
	$('#plan_button').click(function(){
		var plan_station = [];
		var pre_time = $("#time").val();
		var de_price = $("#de_price").val();
		var oil_no = $("#oil_no").val();
		if(pre_time == ''){
			alert('预约时间不能为空');
			return;
		}
		if(de_price == ''){
			alert('降幅不能为空');
			return;
		}
		if(oil_no == ''){
			alert('请选择油号');
			return;
		}
		$("input[class='ace']:checked").each(function(){
			plan_station.push($(this).val());
		})
		$.post('<?php echo base_url().'admin/gasstation/make_update_plan'?>',{
			pre_time:pre_time,
			de_price:de_price,
			oil_no:oil_no,
			id:plan_station
		},function(res){
			if(res){
				location.href="<?php echo base_url().'admin/gasstation/pre_update_price'?>";
			}else{
				alert('error');
			}
		})
		
		
	})
	function delmodal(id){
		$("#delbtn").attr('href','<?php echo base_url().'admin/gasstation/del_gasstation/'?>'+id);
	    $('#delModal').modal('show');
	}
	function use_gasstation(id,type){
		if (type == 0) {
			document.getElementById("user_title").innerText= "确定停用该加油站吗？";   
		} else {
			document.getElementById("user_title").innerText= "确定启用该加油站吗？";
		}
		
		$("#usebtn").attr('href','<?php echo base_url().'admin/gasstation/use_gasstation/'?>'+id+'/'+type);
	    $('#userG').modal('show');
	}
	function delSomeModal(){
		if(checkSelect()){
	    	$('#delsomeModal').modal('show');
		}else{
			alert('请选择正确的记录进行删除');
		}
	}
	$("#delsomebtn").click(function(){
		$("#delForm").submit();
    });
	$("#pre_update").click(function(){
		var plan_station = [];
		$("input[class='ace']:checked").each(function(){
			plan_station.push($(this).val());
		})
		if(plan_station.length != 0){
			$('#pre_plan').modal('show');
		}else{
			location.href="<?php echo base_url().'admin/gasstation/pre_update_price'?>";
		}
	})
	function getGasstationSettlement()
	{
		location.href="<?php echo base_url().'admin/gasstation/getGasstationSettlement'?>";
	}
	</script>